package com.projects.android.views;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.projects.android.R;
import com.projects.android.adapters.FoodsAdapter;
import com.projects.android.utils.SelectedItems;
import com.projects.android.utils.Utils;

public class Menu extends ListActivity {
	private TextView lblRestaurant;
	private TextView lblShipPlace;
	private Intent intent;
	public static Menu MenuView;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		Menu.MenuView = this;
		initFrm();
		loadData();
	}

	private void initFrm() {
		SelectedItems.SelectedFoods.clear();
		lblRestaurant = (TextView) findViewById(R.id.lblRestaurant);
		lblShipPlace = (TextView) findViewById(R.id.lblShipPlace);
		lblRestaurant.setText(SelectedItems.SelectedRestaurant.getName());
		lblShipPlace.setText(SelectedItems.SelectedRestaurant.getDeliveryDistricts());
	}

	public void loadData() {
		// Init data
		if (SelectedItems.AllFoods != null) {
			FoodsAdapter adapter = new FoodsAdapter(this, R.layout.fooditem,
					R.id.lblFoodName, SelectedItems.AllFoods);
			setListAdapter(adapter);
			getListView().setTextFilterEnabled(true);
		}
	}

	public void onListItemClick(ListView parent, View v, int pos, long id) {
		if (pos >= 0 && pos < SelectedItems.AllFoods.size()) {
			SelectedItems.SelectedFood = SelectedItems.AllFoods.get(pos);
			intent = Utils.browseIntent(this, "FoodDetail");
			startActivity(intent);
		}
	}

}
